import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: mac
 * Date: 2022-09-13
 * Time: 23:10
 */
public class TestDemo {
    public static void main(String[] args) {
        //排序Map
        /*Map<Integer,String> map = new TreeMap<>();
        map.put(1,"蔡徐坤");
        map.put(2,"刘亦菲");
        System.out.println(map);

        Map<Integer,String> map1 = new HashMap<>();
        map1.put(1,"蔡徐坤");
        map1.put(2,"刘亦菲");
        System.out.println(map1);*/

        Map<String,String> map = new TreeMap<>();
        map.put("及时雨","蔡徐坤");
        map.put("国名女神","刘亦菲");
        System.out.println(map);

        Map<String,String> map1 = new HashMap<>();
        map1.put("及时雨","蔡徐坤");
        map1.put("国名女神","刘亦菲");
        System.out.println(map1);
    }
    public static void main4(String[] args) {
        //hashMap基本结构
        Map<String,String> map = new HashMap<>();
        map.put("鸡神","蔡徐坤");
        map.put("国名女神","刘亦菲");
        System.out.println(map);
        System.out.println("===========");
        //Set数据类型，重新组装为set数据类型
        Set<Map.Entry<String,String>> entrySet = map.entrySet();
        for (Map.Entry<String,String> entry:entrySet
             ) {
            System.out.println("key: " + entry.getKey() + "value: " + entry.getValue());
        }
        

    }
    public static void main3(String[] args) {
        Map<String,String> map = new HashMap<>();
        map.put("国名女神","刘亦菲");
        map.put("鸡神","蔡徐坤");

        String ret = map.getOrDefault("鸡你太美","嘎威");
        System.out.println(ret);
        boolean flg = map.containsKey("鸡神");
        System.out.println("flg");


        Map<String,String> map1 = new TreeMap<>();
    }
    public static void main2(String[] args) {
        Collection<String> collection = new ArrayList<String>();
        collection.add("hello");
        collection.add("gawei");

        //System.out.println(collection);
        //Object[] objects = collection.toArray();

        //JVM对数据的处理：不建议整体的进行数据类型转换
        //可以理解为数组虽然整体返回值转换了，但数组内元素未发生变化，故会报错
        String[] strings = (String[])collection.toArray();
        System.out.println(Arrays.toString(strings));//报错

        /*collection.clear();
        System.out.println("==========");
        System.out.println(collection);
        System.out.println(collection.isEmpty());*/

    }
    public static void main1(String[] args) {
        //泛型
        Collection<String> collection = new ArrayList<String>();
        collection.add("hello");
        collection.add(" gawei");
        System.out.println(collection);
        //collection.add(1);

        //尖括号当中放的类型一定要是类的类型 不能是简单的基本类型
        Collection<Integer> collection1 = new ArrayList<Integer>();
        collection1.add(1);
        collection1.add(2);
        collection1.add(3);
    }
}

